//
//  LFBShopppingTrolleyBtn.m
//  LFBLoveFreshBee
//
//  Created by 丁鼎 on 16/8/19.
//  Copyright © 2016年 丁鼎. All rights reserved.
//

#import "LFBShopppingTrolleyBtn.h"

@implementation LFBShopppingTrolleyBtn{
    UILabel *_label;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    UILabel *label = [[UILabel alloc]init];
    _label = label;
    label.font = [UIFont systemFontOfSize:9];
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor whiteColor];
    label.backgroundColor = [UIColor redColor];
    
    [self addSubview:label];
    
    label.hidden = YES;
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(actionAddProductNumber) name:ADD_PRODUCTNUMBER object:nil];
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    self.imageView.orgin = CGPointMake(self.width/2-self.imageView.width/2, 0);
    
    self.titleLabel.orgin = CGPointMake(self.width/2-self.titleLabel.width/2, self.imageView.height+4.5);
    
    _label.frame = CGRectMake(self.imageView.width, -5, self.imageView.width/2+5, self.imageView.height/2+5);
    
    //避免多次执行，不信打11111
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _label.layer.cornerRadius = _label.width/2;
        _label.layer.masksToBounds = YES;
    });
    
}

int num = 0;

- (void)actionAddProductNumber
{
    _label.hidden = NO;
    _label.text = [NSString stringWithFormat:@"%d",++num];
    CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
    animation.keyPath = @"transform.scale";
    animation.values = @[@1.0,@1.3,@0.9,@1.15,@0.95,@1.02,@1.0];
    animation.duration = 1;
    animation.calculationMode = kCAAnimationCubic;
    //把动画添加上去就OK了
    [_label.layer addAnimation:animation forKey:nil];
    
}



@end
